<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.6/axios.min.js"></script>
</head>
<body>
    <script>


        axios.interceptors.request.use(config=>{

        })

        // 响应拦截器
        // then(resfn,reafn);
        axios.interceptors.response.use(res=>{
            console.log("成功的响应拦截器");
            return res;
        },rea=>{
            console.log("失败的响应拦截器");
            // 统一处理错误
            if(rea.response.status === 404){
                return '抱歉，地址有误。'
                // throw '123';
            }
            return rea;
        })

        axios('http://localhost:3000/students123').then(val=>{
            console.log(val);
        },rea=>{
            console.log("失败"+rea);
        });

        axios('http://localhost:3000/students').then(val=>{
            console.log(val);
        });

        // axios('http://localhost:3000/students123').then(val=>{
        //     console.log(val);
        // },rea=>{
        //     // 处理失败
        //     console.log(rea);
        // });

        // (async function(){
        //    try{
        //     let res = await axios('http://localhost:3000/students123');
        //     console.log(res);
        //    }
        //    catch(err){
        //     alert('错了'+err.message);
        //    }
        // })()


    </script>
</body>
</html>